using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Stratman.Web.VSTS
{
    /// <summary>
    /// Collection of time types that are relevant for this project.
    /// </summary>
    public class TimeAmountCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Creates a new element to add to the collection.
        /// </summary>
        /// <returns>
        /// A new TimeAmount object.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new TimeAmount();
        }

        /// <summary>
        /// Gets value to use as the key for a specific element in this collection.
        /// </summary>
        /// <param name="element">
        /// Element whose key we are to retrieve.
        /// </param>
        /// <returns>
        /// The Label property of the specified TimeAmount object.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((TimeAmount)element).Label;
        }

        /// <summary>
        /// String indexer for the collection; uses the Label property of each TimeAmount object as
        /// the index.
        /// </summary>
        /// <param name="label">
        /// Value of the Label property of the TimeAmount object that we are to return.
        /// </param>
        /// <returns>
        /// TimeAmount object with the specified label.
        /// </returns>
        public new TimeAmount this[string label]
        {
            get
            {
                return (base.BaseGet(label) as TimeAmount);
            }

            set
            {
                if (base.BaseGet(label) != null)
                    base.BaseRemove(label);

                this.BaseAdd(value);
            }
        }

        /// <summary>
        /// Numeric indexer for the collection.
        /// </summary>
        /// <param name="index">
        /// Index in the collection whose contents we are to return.
        /// </param>
        /// <returns>
        /// TimeAmount object at the specified index.
        /// </returns>
        public TimeAmount this[int index]
        {
            get
            {
                return (base.BaseGet(index) as TimeAmount);
            }

            set
            {
                if (base.BaseGet(index) != null)
                    base.BaseRemoveAt(index);

                this.BaseAdd(index, value);
            }
        }
    }
}
